home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / piglat10.zip / PIGLATIN.L < prev   
Text File  |  1993-06-16  |  3KB  |  149 lines

  1.  /* piglatin.l */
  2.  /* piglatin version 1.00
  3.  ** 06/16/93
  4.  ** Duane Paulson <ci922@cleveland.freenet.edu> "dap"
  5.  ** Piglatin text filter.
  6.  **
  7.  ** NOTE that this program was developed using FLEX, not LEX.
  8.  ** When compiling using lex, some tweaking of the %e, %p, %n,
  9.  ** %n, %k, %a, and %o parameters may be necessary. Since flex
  10.  ** does not use these parameters, I cannot generate recommended
  11.  ** values. Hint: If you get the "Parse tree to big" lex error
  12.  ** message, you can fix it by tweaking these parameters.
  13.  ** I suggest you run the MAN page for lex, or locate the
  14.  ** flex code and use that.
  15.  **
  16.  ** Public domain. Use at your own risk.
  17.  */
  18.  
  19.  /*************************************************************************
  20.                 REVISION LOG
  21.  when      ver   who  change
  22.  --------  ----  ---  -----------------------------------------------------
  23.  06/16/93  1.00  dap  Initial release.
  24.  *************************************************************************/
  25.  
  26. LETTER    [A-Za-z'\-]
  27. VOWEL    [AEIOUaeiou]
  28. CONSONANT [A-DF-HJ-NP-TV-Za-df-hj-np-tv-z'\-]
  29. SW   [ \t\"(\[{\.,!?:;_*]
  30. EW   [ \t\.,\"\]}!?):;_*]
  31.  
  32.     #define PUTLAST unput(*(yytext+strlen(yytext)-1));\
  33.         *(yytext+strlen(yytext))='\0';
  34.  
  35.     #define MASKIT mask=*(yytext+strlen(yytext)-1)&32;
  36.     #define PUT_AY fputc('A'|mask, yyout); fputc('Y'|mask, yyout);
  37.     #define PUT_WAY fputc('W'|mask, yyout); PUT_AY;
  38.  
  39.     #include <string.h>
  40.     #include <ctype.h>
  41.  
  42.     int    mask;
  43.     char    cons[128];
  44.     int    conlen;
  45.  
  46.     #ifdef __STDC__
  47.     void    put_midstring(int start);
  48.     void    strip_cons(int start);
  49.     #else
  50.     int    put_midstring();
  51.     int    strip_cons();
  52.     #endif
  53.  
  54. %%
  55.  
  56. {SW}-+{EW}    |
  57. ^-+{EW}        PUTLAST; ECHO;
  58. ^-+$        |
  59. {SW}-+$        ECHO;
  60.  
  61. ^{VOWEL}{LETTER}*{EW}        |
  62. {SW}{VOWEL}{LETTER}*{EW}    {
  63.     PUTLAST;
  64.     MASKIT;
  65.     ECHO;
  66.     PUT_WAY;
  67.                 }
  68.  
  69. ^{VOWEL}{LETTER}*$        |
  70. {SW}{VOWEL}{LETTER}*$        {
  71.     MASKIT;
  72.     ECHO;
  73.     PUT_WAY;
  74.                 }
  75.  
  76. {SW}{CONSONANT}{LETTER}*{EW}    {
  77.     PUTLAST;
  78.     MASKIT;
  79.     fputc(*yytext, yyout);
  80.     strip_cons(1);
  81.     put_midstring(1+conlen);
  82.                 }
  83.  
  84. {SW}{CONSONANT}{LETTER}*$    {
  85.     MASKIT;
  86.     fputc(*yytext, yyout);
  87.     strip_cons(1);
  88.     put_midstring(1+conlen);
  89.                 }
  90.  
  91. ^{CONSONANT}{LETTER}*{EW}     {
  92.     PUTLAST;
  93.     MASKIT;
  94.     strip_cons(0);
  95.     put_midstring(conlen);
  96.                 }
  97.     
  98. ^{CONSONANT}{LETTER}*$        {
  99.     MASKIT;
  100.     strip_cons(0);
  101.     put_midstring(conlen);
  102.                 }
  103.     
  104. %%
  105.  
  106. #ifdef __STDC__
  107. void strip_cons(int start)
  108. #else
  109. strip_cons(start)
  110. int start;
  111. #endif
  112. {
  113.     conlen=0;
  114.     while(strchr("bcdfghjklmnpqrstvwxyz", tolower(*(yytext+start)))!=NULL)
  115.     {
  116.         *(cons+conlen)=*(yytext+start);
  117.         start++;
  118.         conlen++;
  119.     }
  120.     *(cons+conlen)='\0';
  121. }
  122.  
  123. #ifdef __STDC__
  124. void put_midstring(int start)
  125. #else
  126. put_midstring(start)
  127. int start;
  128. #endif
  129. {
  130.     if(strlen(yytext)>start)
  131.         fputc(toupper(*(yytext+start))|
  132.           (*(yytext+start-conlen)&32), yyout);
  133.     if(strlen(yytext)>(start+1))
  134.         fprintf(yyout, "%s", yytext+start+1);
  135.     fputc(toupper(*cons)|mask, yyout);
  136.     conlen=1;
  137.     while(*(cons+conlen)!='\0')
  138.     {
  139.         fputc(toupper(*(cons+conlen))|mask, yyout);
  140.         conlen++;
  141.     }
  142.     PUT_AY;
  143. }
  144.  
  145. main()
  146. {
  147.     yylex();
  148. }
  149.